package com.ms.common.util;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.log.Log;

public class ChangbaUrlSignUtil {
	private static final String changba_key="6915d083bb2bb92eaa3754d5a7005dbc";
	private static Log logger=Log.getLog(ChangbaUrlSignUtil.class);

	/**
	 * 获取加密的sign
	 * @return
	 */
	public static String getSign(Map reqParam){
	        Collection<String> keyset= reqParam.keySet();  
	        List<String> list = new ArrayList<String>(keyset);  
	          
	        //对key键值按字典升序排序  
	        Collections.sort(list);  
	          
	        String signStr="";
	        for (int i = 0; i < list.size(); i++) {  
	        	signStr=signStr+list.get(i)+"="+reqParam.get(list.get(i))+"&";
	        } 
	        signStr=signStr.substring(0,signStr.length()-1);
	        signStr+=changba_key;
	    	return MD5.GetMD5Code(signStr);
		}
	
	/**
	 * 获取加密的sign
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	public static String getSigns(Map<String, String[]> reqParam) throws UnsupportedEncodingException{
	        Collection<String> keyset= reqParam.keySet();  
	        List<String> list = new ArrayList<String>(keyset);  
	          
	        //对key键值按字典升序排序  
	        Collections.sort(list);  
	          
	        String signStr="";
	        for (int i = 0; i < list.size(); i++) {  
	      //  	signStr=signStr+list.get(i)+"="+GameListController.isUtf8Url(reqParam.get(list.get(i))[0])+"&";
//	        	signStr=signStr+list.get(i)+"="+new String(reqParam.get(list.get(i))[0].getBytes("ISO8859_1"),"UTF-8")+"&";
	        } 
	        signStr=signStr.substring(0,signStr.length()-1);
	        signStr+=changba_key;
	        logger.info("getSigns***********************"+signStr+"********************************************************");
	    	return MD5.GetMD5Code(signStr);
	}
	//http://www.mysongktv.cn:9090/msExam/matchBas/getMatchByShopId?shopId=1&time=1470377793&sign=642eb63705314735628c864356e2edc3


	
	public static void main(String[] args) {
		Map param=new HashMap<>();
		param.put("shopId", 1+"");
		param.put("time", "1470382449663");
		System.out.println(getSign(param));
	}
		
}
